var express = require('express');
const BusinessModel = require('../models/BusinessGoods');
const RouterModel = require('../models/RoutesModel');
const MenuModel = require('../models/MenuModel');
let { oneModel, one1Model, one2Model, twoModel,threeModel } = require('../module/index')
var router = express.Router();
const {testModel,test2Model}=require('../module/db')

/* GET home page. */
// router.post('/login', function(req, res, next) {
//   res.render('index', { title: 'Express' });
// });

router.get('/router/list', async (req, res) => {
  // 动态路由
  const { key } = req.query
  const data = await RouterModel.find({ key }).lean()
  const routerObj = {}
  data.forEach(item => {
    routerObj[item._id] = item
  })
  const routerList = []
  data.forEach(item => {
    if (!item.router_id) {
      routerList.push(item)
    } else {
      if (!routerObj[item.router_id].children) {
        routerObj[item.router_id].children = []
      }
      routerObj[item.router_id].children.push(item)
    }
  })
  // 动态菜单
  const menuList = await MenuModel.find({ type: key })
  res.send({
    ActionType: "OK",
    routerList,
    menuList
  })
})

router.get("/getlist", async (req, res) => {
  const data = await oneModel.find()
  res.send({ code: 200, data })
})

router.get("/getlist11", async (req, res) => {
  const data = await one1Model.find()
  res.send({ code: 200, data })
})

router.get("/getlist111", async (req, res) => {
  const data = await one2Model.find()
  res.send({ code: 200, data })
})

router.get("/getlist2", async (req, res) => {
  const data = await twoModel.find()
  res.send({ code: 200, data })
})

router.get("/getlist3", async (req, res) => {
  const data = await threeModel.find()
  res.send({ code: 200, data })
})



module.exports = router;
